//
//  CustomHouseTypeViewController.m
//  customer
//
//  Created by Holothurian on 2018/11/2.
//  Copyright © 2018年 yinlong. All rights reserved.
//

#import "CustomHouseTypeViewController.h"
#import "CustomBaseShowInTableViewCell.h"
#import "CustomCaseTypeViewController.h"

static NSString *CellIdentifier = @"CellIdentifier";
@interface CustomHouseTypeViewController ()<UITableViewDelegate,UITableViewDataSource>

@end

@implementation CustomHouseTypeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"户型选择";
    self.tableView.frame = CGRectMake(0, NAVIGATION_BAR_HEIGHT, F_DEVICE_W, F_DEVICE_H - NAVIGATION_BAR_HEIGHT);
    [self.tableView registerClass:[CustomBaseShowInTableViewCell class] forCellReuseIdentifier:CellIdentifier];
}

- (void)loadDataList{
    AutoWeakSelf
    [self showLoading];
    NSDictionary *dict = @{@"customized_id":self.caseListModel.customized_id?:@"-1"};
    [[QYNetManager sharedManager]POST:kGetCustomizedHuxings parameters:dict andApiTyp:CustomerApiTypGetOrders SuccessBlock:^(id responseObject) {
        [weakSelf hideLoading];
        if (self.dataList.count) {
            [self.dataList removeAllObjects];
        }
        if ([responseObject[@"status"] isEqualToString:@"error"]) {
            [weakSelf showErrorTipWithTitle:responseObject[@"error"]];
        }else{
            NSArray *dataSource = responseObject[@"data"];
            [weakSelf.dataList addObjectsFromArray:[NSArray yy_modelArrayWithClass:[CustomHouseTypeModel class] json:dataSource]];
            weakSelf.tableView.showEmpty = ([self.dataList count] == 0);
        }
        [weakSelf.tableView reloadData];
    } Failure:^(NSError *error) {
        [weakSelf hideLoading];
        [weakSelf showErrorTipWithTitle:CustomerPoolNetStr];
    }];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return [self.dataList count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    CustomBaseShowInTableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    CustomHouseTypeModel *model = self.dataList[indexPath.row];
    [cell cellForCustomHouseTypeLayout:model];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    CustomCaseTypeViewController *house = [[CustomCaseTypeViewController alloc]init];
    house.houseTypeModel = self.dataList[indexPath.row];
    house.caseListModel = self.caseListModel;
    TAB_PUSH(self, house, YES);
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 180.f;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
